package com.lb.service.impl;

import com.lb.entity.TbSalaSeat;
import com.lb.dao.TbSalaSeatDao;
import com.lb.service.TbSalaSeatService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TbSalaSeat)表服务实现类
 *
 * @author libo
 * @since 2024-09-13 11:30:06
 */
@Service("tbSalaSeatService")
public class TbSalaSeatServiceImpl implements TbSalaSeatService {
    @Resource
    private TbSalaSeatDao tbSalaSeatDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbSalaSeat queryById(Integer id) {
        return this.tbSalaSeatDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tbSalaSeat 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbSalaSeat> queryByPage(TbSalaSeat tbSalaSeat, PageRequest pageRequest) {
        long total = this.tbSalaSeatDao.count(tbSalaSeat);
        return new PageImpl<>(this.tbSalaSeatDao.queryAllByLimit(tbSalaSeat, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tbSalaSeat 实例对象
     * @return 实例对象
     */
    @Override
    public TbSalaSeat insert(TbSalaSeat tbSalaSeat) {
        this.tbSalaSeatDao.insert(tbSalaSeat);
        return tbSalaSeat;
    }

    /**
     * 修改数据
     *
     * @param tbSalaSeat 实例对象
     * @return 实例对象
     */
    @Override
    public TbSalaSeat update(TbSalaSeat tbSalaSeat) {
        this.tbSalaSeatDao.update(tbSalaSeat);
        return this.queryById(tbSalaSeat.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tbSalaSeatDao.deleteById(id) > 0;
    }
}
